import com.google.gson.*;

import java.util.ArrayList;
import java.util.List;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import config.*;



public class Controller {
	public void readConfig() {
		Gson gson = new Gson();
		
		try {
			BufferedReader br = new BufferedReader(new FileReader("test.json"));
			TaskConfig[] tcs = gson.fromJson(br, TaskConfig[].class);
			for(TaskConfig tc : tcs) {
				System.out.println(tc);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void writeConfig() {
		List<TaskConfig> tcs = new ArrayList<TaskConfig>();
		tcs.add(new TaskConfig());
		tcs.add(new TaskConfig());
		
		for(int i = 0; i < tcs.size(); i++) {
			tcs.get(i).workingsetType = "array";
			tcs.get(i).elementType = "int";
			tcs.get(i).strideScale = new MScale(10, 100, 20);
			tcs.get(i).workingsetSizeScale = new MScale(100, 1000, 200);
			tcs.get(i).threadNumScale = new MScale(1, 64, 1);
			tcs.get(i).behavior = "sequential read";
			tcs.get(i).tags = new ArrayList<String>();
			tcs.get(i).tags.add("test");
			tcs.get(i).tags.add("array");
			tcs.get(i).tags.add("int");
		}
		
		Gson gson = new Gson();
		String jsonStr = gson.toJson(tcs);
				
		
		try {
			FileWriter f = new FileWriter("test.json");
			f.write(jsonStr);
			f.flush();
			f.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
